package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.itheima.dao.MenuDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Menu;
import com.itheima.dao.PermissionDao;
import com.itheima.pojo.Role;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 用户服务
 */

@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDao menuDao;

    @Autowired
    private PermissionDao permissionDao;

    @Override
    public List<Menu> findAll() {
        return menuDao.findAll();
    }

    //分页查
    public PageResult pageQuery() {

        //PageHelper.startPage(currentPage,pageSize);
        Page<Menu> page = menuDao.findByCondition();
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Map map) {
        menuDao.add(map);
    }

    @Override
    public void update(Map map) {
        /*menuDao.delete((Integer)map.get("id"));
        menuDao.add(map);*/
        menuDao.update(map);
    }

    @Override
    public void delete(Integer id) {
        menuDao.delete(id);
    }

}
